<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="classes" match="//class" use="@name"/>

<xsl:template match="/">

<javascript>
	<xsl:for-each select="//class[generate-id() = generate-id(key('classes',@name)[1])]">
	<xsl:sort order="ascending" select="@name"/>
	<!-- MAKE EM UNIQUE -->
	<!-- <xsl:if test="instance-methods/method"> -->
	<class>
		<xsl:attribute name="type">
			<xsl:value-of select="@name"/>
		</xsl:attribute>
		<xsl:attribute name="superclass">
			<xsl:choose>
				<xsl:when test="@extend">
					<xsl:value-of select="@extend"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:text>Object</xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:attribute>
		<constructors>
			<constructor>
				<!-- Check to see if it's static -->
				<xsl:choose>
					<xsl:when test="constructor_vars/var[@name='static']">
						<xsl:attribute name="scope">static</xsl:attribute>
					</xsl:when>
					<xsl:otherwise>
						<xsl:attribute name="scope">instance</xsl:attribute>
					</xsl:otherwise>
				</xsl:choose>
				
				<description>
					<xsl:value-of select="constructor_detail"/>
				</description>
				<parameters>
				
				</parameters>
				<return-types>
					<return-type>
						<xsl:attribute name="type">
							<xsl:choose>
								<xsl:when test="constructor_vars/var[@name='type']/value">
									<xsl:value-of select="constructor_vars/var[@name='type']/value"/>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="@name"/>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:attribute>
					</return-type>
				</return-types>
			</constructor>
		</constructors>
		<properties>
			<xsl:for-each select="instance-fields/field">
				<property>
					<xsl:attribute name="name">
						<xsl:value-of select="@name"/>
					</xsl:attribute>
					<xsl:attribute name="type">
						<xsl:value-of select="vars/var[@name='type']/value"/>
					</xsl:attribute>
					<xsl:attribute name="scope">
						<xsl:text>instance</xsl:text>
					</xsl:attribute>
				</property>
			</xsl:for-each>
			<xsl:for-each select="class-fields/field">
				<property>
					<xsl:attribute name="name">
						<xsl:value-of select="@name"/>
					</xsl:attribute>
					<xsl:attribute name="type">
						<xsl:value-of select="vars/var[@name='type']/value"/>
					</xsl:attribute>
					<xsl:attribute name="scope">
						<xsl:text>static</xsl:text>
					</xsl:attribute>
					<description>
						<xsl:value-of select="field-description"/>
					</description>
				</property>
			</xsl:for-each>
		</properties>
		<!-- ADD MIXINS HERE -->
		<methods>
			<xsl:for-each select="instance-methods/method">
				<method>
					<xsl:attribute name="name">
						<xsl:value-of select="@mapped_name"/>
					</xsl:attribute>
					<xsl:attribute name="scope">
						<xsl:text>instance</xsl:text>
					</xsl:attribute>
					<parameters>
					</parameters>
				</method>
			</xsl:for-each>
		</methods>
	</class>
	<!-- </xsl:if> -->
	</xsl:for-each>
</javascript>

</xsl:template>

</xsl:stylesheet>